package com.kehao.leetcode.jzoffer;

import org.junit.Test;

/**
 * @author Kehao.Chen
 * @version 1.0
 * @date 2022/6/7 9:46
 */
public class JZSolution001 {
    public int divide(int a, int b) {
        if(a == Integer.MIN_VALUE && b ==-1 ){
            return Integer.MAX_VALUE;
        }
        boolean flag = !(a>0^b>0);
        a = Math.abs(a);
        b = Math.abs(b);
        int sum = 0;
        for (int i = 31; i >=0; i--) {
            if((a>>>i)-b>=0){
                sum+=1<<i;
                a = a - (b<<i);
            }
        }
        return flag?sum:-sum;
    }

    @Test
    public void test01(){
        int result = divide(15, 2);
        System.out.println(result);
    }
}
